class MyCircularDeque {

    private int[] arr;
    private int head;
    private int tail;
    private int size;
    public MyCircularDeque(int k) {
        arr = new int[k];
        size = 0;
        head = 0;
        tail = 0;
    }

    public boolean insertFront(int value) {
        if(isFull()){
            return false;
        }
        if(head == 0) {
            head = arr.length - 1;
        }else{
            head = head - 1;
        }
        arr[head] = value;
        size++;
        return true;
    }

    public boolean insertLast(int value) {
        if(isFull()){
            return false;
        }
        arr[tail] = value;
        if(tail == arr.length-1){
            tail = 0;
        }else{
            tail++;
        }
        size++;
        return true;
    }

    public boolean deleteFront() {
        if(isEmpty()){
            return false;
        }
        if(head == arr.length - 1) {
            head = 0;
        }else {
            head = head + 1;
        }
        size--;
        return true;
    }

    public boolean deleteLast() {
        if(isEmpty()) return false;
        if(tail == 0) {
            tail = arr.length - 1;
        }else{
            tail--;
        }
        size--;
        return true;
    }

    public int getFront() {
        if(isEmpty()) return -1;
        return arr[head];
    }

    public int getRear() {
        if(isEmpty()) return -1;
        if(tail == 0) return arr[arr.length - 1];
        return arr[tail-1];
    }

    public boolean isEmpty() {
        return size == 0;
    }

    public boolean isFull() {
        return  size == arr.length;
    }
}

/**
 * Your MyCircularDeque object will be instantiated and called as such:
 * MyCircularDeque obj = new MyCircularDeque(k);
 * boolean param_1 = obj.insertFront(value);
 * boolean param_2 = obj.insertLast(value);
 * boolean param_3 = obj.deleteFront();
 * boolean param_4 = obj.deleteLast();
 * int param_5 = obj.getFront();
 * int param_6 = obj.getRear();
 * boolean param_7 = obj.isEmpty();
 * boolean param_8 = obj.isFull();
 */